﻿using System.Collections.Specialized;
using System.Web.Security;
using AspAuthentication.Core;
using AspAuthentication.Persistence;

namespace AspAuthentication.Interfaces
{
    /// <summary>
    /// Defines the contract which any implementation of IPortalMembershipProvider must satisfy
    /// </summary>
    public interface IPortalMembershipProvider
    {
        /// <summary>
        /// Creates the user.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="status">The status.</param>
        /// <returns></returns>
        MembershipUser CreateUser(DomainUser user, out MembershipCreateStatus status);
        /// <summary>
        /// Creates the user.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <param name="email">The email.</param>
        /// <param name="status">The status.</param>
        /// <returns></returns>
        MembershipUser CreateUser(string username, string password, string email, out MembershipCreateStatus status);
        /// <summary>
        /// Handles the password hash.
        /// </summary>
        /// <param name="password">The password.</param>
        /// <returns></returns>
        string HandlePasswordHash(string password);
        /// <summary>
        /// Creates the user.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <param name="email">The email.</param>
        /// <param name="passwordQuestion">The password question.</param>
        /// <param name="passwordAnswer">The password answer.</param>
        /// <param name="isApproved">if set to <c>true</c> [is approved].</param>
        /// <param name="providerUserKey">The provider user key.</param>
        /// <param name="status">The status.</param>
        /// <returns></returns>
        MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status);
        /// <summary>
        /// Changes the password question and answer.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <param name="newPasswordQuestion">The new password question.</param>
        /// <param name="newPasswordAnswer">The new password answer.</param>
        /// <returns></returns>
        bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer);
        /// <summary>
        /// Gets the password.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="answer">The answer.</param>
        /// <returns></returns>
        string GetPassword(string username, string answer);
        /// <summary>
        /// Changes the password.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="oldPassword">The old password.</param>
        /// <param name="newPassword">The new password.</param>
        /// <returns></returns>
        bool ChangePassword(string username, string oldPassword, string newPassword);
        /// <summary>
        /// Resets the password.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="answer">The answer.</param>
        /// <returns></returns>
        string ResetPassword(string username, string answer);
        /// <summary>
        /// Updates the user.
        /// </summary>
        /// <param name="user">The user.</param>
        void UpdateUser(MembershipUser user);
        /// <summary>
        /// Validates the user.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <returns></returns>
        bool ValidateUser(string username, string password);
        /// <summary>
        /// Logins the user.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <returns></returns>
        bool LoginUser(string username, string password);
        /// <summary>
        /// Logouts the user.
        /// </summary>
        void LogoutUser();
        /// <summary>
        /// Unlocks the user.
        /// </summary>
        /// <param name="userName">Name of the user.</param>
        /// <returns></returns>
        bool UnlockUser(string userName);
        /// <summary>
        /// Gets the user.
        /// </summary>
        /// <param name="providerUserKey">The provider user key.</param>
        /// <param name="userIsOnline">if set to <c>true</c> [user is online].</param>
        /// <returns></returns>
        MembershipUser GetUser(object providerUserKey, bool userIsOnline);
        /// <summary>
        /// Gets the user.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="userIsOnline">if set to <c>true</c> [user is online].</param>
        /// <returns></returns>
        MembershipUser GetUser(string username, bool userIsOnline);
        /// <summary>
        /// Gets the user name by email.
        /// </summary>
        /// <param name="email">The email.</param>
        /// <returns></returns>
        string GetUserNameByEmail(string email);
        /// <summary>
        /// Deletes the user.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="deleteAllRelatedData">if set to <c>true</c> [delete all related data].</param>
        /// <returns></returns>
        bool DeleteUser(string username, bool deleteAllRelatedData);
        /// <summary>
        /// Gets all users.
        /// </summary>
        /// <param name="pageIndex">Index of the page.</param>
        /// <param name="pageSize">Size of the page.</param>
        /// <param name="totalRecords">The total records.</param>
        /// <returns></returns>
        MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords);
        /// <summary>
        /// Gets the number of users online.
        /// </summary>
        /// <returns></returns>
        int GetNumberOfUsersOnline();
        /// <summary>
        /// Finds the name of the users by.
        /// </summary>
        /// <param name="usernameToMatch">The username to match.</param>
        /// <param name="pageIndex">Index of the page.</param>
        /// <param name="pageSize">Size of the page.</param>
        /// <param name="totalRecords">The total records.</param>
        /// <returns></returns>
        MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords);
        /// <summary>
        /// Finds the users by email.
        /// </summary>
        /// <param name="emailToMatch">The email to match.</param>
        /// <param name="pageIndex">Index of the page.</param>
        /// <param name="pageSize">Size of the page.</param>
        /// <param name="totalRecords">The total records.</param>
        /// <returns></returns>
        MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords);
        /// <summary>
        /// Initializes the specified name.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="config">The config.</param>
        void Initialize(string name, NameValueCollection config);
        /// <summary>
        /// Gets a value indicating whether [enable password retrieval].
        /// </summary>
        /// <value>
        /// 	<c>true</c> if [enable password retrieval]; otherwise, <c>false</c>.
        /// </value>
        bool EnablePasswordRetrieval { get; }
        /// <summary>
        /// Gets a value indicating whether [enable password reset].
        /// </summary>
        /// <value><c>true</c> if [enable password reset]; otherwise, <c>false</c>.</value>
        bool EnablePasswordReset { get; }
        /// <summary>
        /// Gets a value indicating whether [requires question and answer].
        /// </summary>
        /// <value>
        /// 	<c>true</c> if [requires question and answer]; otherwise, <c>false</c>.
        /// </value>
        bool RequiresQuestionAndAnswer { get; }
        /// <summary>
        /// Gets or sets the name of the application.
        /// </summary>
        /// <value>The name of the application.</value>
        string ApplicationName { get; set; }
        /// <summary>
        /// Gets the max invalid password attempts.
        /// </summary>
        /// <value>The max invalid password attempts.</value>
        int MaxInvalidPasswordAttempts { get; }
        /// <summary>
        /// Gets the password attempt window.
        /// </summary>
        /// <value>The password attempt window.</value>
        int PasswordAttemptWindow { get; }
        /// <summary>
        /// Gets a value indicating whether [requires unique email].
        /// </summary>
        /// <value><c>true</c> if [requires unique email]; otherwise, <c>false</c>.</value>
        bool RequiresUniqueEmail { get; }
        /// <summary>
        /// Gets the password format.
        /// </summary>
        /// <value>The password format.</value>
        MembershipPasswordFormat PasswordFormat { get; }
        /// <summary>
        /// Gets the length of the min required password.
        /// </summary>
        /// <value>The length of the min required password.</value>
        int MinRequiredPasswordLength { get; }
        /// <summary>
        /// Gets the min required non alphanumeric characters.
        /// </summary>
        /// <value>The min required non alphanumeric characters.</value>
        int MinRequiredNonAlphanumericCharacters { get; }
        /// <summary>
        /// Gets the password strength regular expression.
        /// </summary>
        /// <value>The password strength regular expression.</value>
        string PasswordStrengthRegularExpression { get; }
        /// <summary>
        /// Gets the description.
        /// </summary>
        /// <value>The description.</value>
        string Description { get; }
        /// <summary>
        /// Gets the name.
        /// </summary>
        /// <value>The name.</value>
        string Name { get; }
        /// <summary>
        /// Gets or sets the name of the connection string.
        /// </summary>
        /// <value>The name of the connection string.</value>
        string ConnectionStringName { get; set; }/// <summary>
        /// Gets the unit of work.
        /// </summary>
        /// <value>The unit of work.</value>
        IUnitOfWork UnitOfWork { get; }
    }
}